/*----------------------绑定手势---------------------*/
//位置移动
mc.on("panstart",function(e){
	  mapScale = parseFloat($$('.map-container').data('scale'));
	  //获取现在的坐标
	  mapTop = parseFloat($$('.map-container').data('axisY'));
	  mapLeft = parseFloat($$('.map-container').data('axisX'));
});
mc.on("panmove",function(e){
	  //获取位移
	  var dx = parseFloat(e.deltaX);
	  var dy = parseFloat(e.deltaY);
	  mapdx = dx;
	  mapdy = dy;
	  var cmapleft = mapLeft+dx;
	  var cmaptop  = mapTop+dy;
	  //移动
	  $$('.map-container').transform('translate('+cmapleft+'px,'+cmaptop+'px) scale('+mapScale+')');
	  //console.log(e);
});
mc.on("panend",function(){
	  mapTop  += mapdy;
	  mapLeft += mapdx;
	  $$('.map-container').data('axisY',mapTop);
	  $$('.map-container').data('axisX',mapLeft);
});
//地图缩放
mc.on("pinchstart",function(e){
	  mapTop = parseFloat($$('.map-container').data('axisY'));
	  mapLeft = parseFloat($$('.map-container').data('axisX'));
	  //获取现在比例
	  mapScale = parseFloat($$('.map-container').data('scale'));
});
mc.on("pinchmove",function(e){
	  //获取比例
	  var dscale = e.scale;
	  mapdscale = dscale
	  var cmapscale = mapScale*dscale;
	  //缩放
	  $$('.map-container').transform('translate('+mapLeft+'px,'+mapTop+'px) scale('+cmapscale+')');

});
mc.on("pinchend",function(){
	  mapScale   *= mapdscale;
	  $$('.map-container').data('scale',mapScale);
});
//点击地图
mc.on("tap",function(e){
	  // console.log('page('+e.pointers[0].pageX+';'+e.pointers[0].pageY+')clientX('+e.pointers[0].clientX+','+e.pointers[0].clientY+')'+'tapcenter('+e.center.x+','+e.center.y+')');
	  var scale = parseFloat($$('.map-container').data('scale'));
	  var res = setMarkerPos('.loc-icon',e.center,scale);
	  markerBlock = res.markerblock;
	  markerPos = res.markerpos;
	  markerFloor = res.markerfloor;
	  if(res.markerdisplay){
		  //信息框
		  $$('#findPath .toolbar').show();
		  //信息框文本
		  //var name = '('+res.markerrealpos.x.toString()+','+res.markerrealpos.y.toString()+')';
		  var name = '('+markerBlock[0].toString()+','+markerBlock[1].toString()+')';
		  $$('#findPath .toolbar .loc-name').html(name);
	  }
});
  
$$(document).on('click','.startloc',function(){
	startBlock = markerBlock;
	startFloor = markerFloor;
	//清空路径
	$$('#floor-canvas').attr('height',mapH);
	pathroute = '';
	//清空信息框和marker
	$$('#findPath .toolbar').hide();
	$$('.loc-icon').hide();
	$$('.loc-icon-start').hide();
	$$('.loc-icon-end').hide();
	$$('.marker').removeClass('active');
    //添加新marker
	$$('.loc-icon-start').attr('floor',markerFloor);
	$$('.loc-icon-start').transform('translate('+markerPos.x+'px,'+markerPos.y+'px)');
	$$('.loc-icon-start').addClass('active');
	$$('.loc-icon-start').show();
});
$$(document).on('click','.endloc',function(){
	//起点必须存在
	if(startBlock){
    	endBlock = markerBlock;
    	endFloor = markerFloor;
    	//清空信息框和marker
    	$$('#findPath .toolbar').hide();
    	$$('.loc-icon-end').hide();
    	$$('.loc-icon-end').removeClass('avtive');
    	$$('.loc-icon').hide();
    	$$('.loc-icon').removeClass('avtive');
    	//添加新marker
		$$('.loc-icon-end').attr('floor',markerFloor);
    	$$('.loc-icon-end').transform('translate('+markerPos.x+'px,'+markerPos.y+'px)');
    	$$('.loc-icon-end').addClass('active');
    	$$('.loc-icon-end').show();
    	//寻找路径
  	  	findPath(startFloor,endFloor);
	}else{
		myApp.alert('请先选择起点');
	}
});
$$(document).on('click','.walk-icon',function(){
	if(currentBlockX != 0 && currentBlockY != 0 ){
		//选择定位点为起点
		startBlock = [currentBlockX,currentBlockY];
		//选择当前点为终点
		endBlock = markerBlock;
		endFloor = markerFloor;
		//清空信息框和marker
		$$('#findPath .toolbar').hide();
		$$('.loc-icon').hide();
		$$('.loc-icon-start').hide();
		$$('.loc-icon-end').hide();
		$$('.marker').removeClass('active');
		//添加新marker
		$$('.loc-icon-end').attr('floor',markerFloor);
		$$('.loc-icon-end').transform('translate('+markerPos.x+'px,'+markerPos.y+'px)');
		$$('.loc-icon-end').addClass('active');
		$$('.loc-icon-end').show();
		//console.log(startblock,blocks[startblock[1]][startblock[0]]);
		//console.log(endblock,blocks[endblock[1]][endblock[0]]);
		//寻找路径
	  	findPath();
	}else{
		myApp.alert('无法确定您现在的位置');
	}
});